<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic
  PUBLIC "-//OASIS//DTD DITA Composite//EN" "ditabase.dtd">
<topic id="topic1"><title id="bo20941">CREATE CONVERSION</title><body><p id="sql_command_desc">Defines a new encoding conversion.</p><section id="section2"><title>Synopsis</title><codeblock id="sql_command_synopsis">CREATE [DEFAULT] CONVERSION <varname>name</varname> FOR <varname>source_encoding</varname> TO 
     <varname>dest_encoding</varname> FROM <varname>funcname</varname></codeblock></section><section id="section3"><title>Description</title><p><codeph>CREATE CONVERSION</codeph> defines a new conversion between
character set encodings. Conversion names may be used in the convert
function to specify a particular encoding conversion. Also, conversions
that are marked <codeph>DEFAULT</codeph> can be used for automatic encoding
conversion between client and server. For this purpose, two conversions,
from encoding A to B and from encoding B to A, must be defined. </p><p>To create a conversion, you must have <codeph>EXECUTE</codeph> privilege
on the function and <codeph>CREATE</codeph> privilege on the destination
schema.</p></section><section id="section4"><title>Parameters</title><parml><plentry><pt>DEFAULT</pt><pd>Indicates that this conversion is the default for this particular
source to destination encoding. There should be only one default encoding
in a schema for the encoding pair. </pd></plentry><plentry><pt><varname>name</varname></pt><pd>The name of the conversion. The conversion name may be schema-qualified.
If it is not, the conversion is defined in the current schema. The conversion
name must be unique within a schema. </pd></plentry><plentry><pt><varname>source_encoding</varname></pt><pd>The source encoding name. </pd></plentry><plentry><pt><varname>dest_encoding</varname></pt><pd>The destination encoding name. </pd></plentry><plentry><pt><varname>funcname</varname></pt><pd>The function used to perform the conversion. The function name may
be schema-qualified. If it is not, the function will be looked up in
the path. The function must have the following signature: </pd><pd><codeblock>conv_proc(
    integer,  -- source encoding ID
    integer,  -- destination encoding ID
    cstring,  -- source string (null terminated C string)
    internal, -- destination (fill with a null terminated C string)
    integer   -- source string length
) RETURNS void;</codeblock></pd></plentry></parml></section><section id="section5"><title>Notes</title><p>Note that in this release of Greenplum Database, user-defined functions
used in a user-defined conversion must be defined as <codeph>IMMUTABLE</codeph>.
Any compiled code (shared library files) for custom functions must be
placed in the same location on every host in your Greenplum Database
array (master and all segments). This location must also be in the <codeph>LD_LIBRARY_PATH</codeph>
so that the server can locate the files.</p></section><section id="section6"><title>Examples</title><p>To create a conversion from encoding <codeph>UTF8</codeph> to <codeph>LATIN1</codeph> using
          <codeph>myfunc</codeph>:</p><codeblock>CREATE CONVERSION myconv FOR 'UTF8' TO 'LATIN1' FROM myfunc;</codeblock></section><section id="section7"><title>Compatibility</title><p>There is no <codeph>CREATE CONVERSION</codeph> statement in the SQL
            standard, but there is a <codeph>CREATE TRANSLATION</codeph>
            statement that is very similar in purpose and syntax.</p></section><section id="section8"><title>See Also</title><p><codeph><xref href="ALTER_CONVERSION.xml#topic1" type="topic" format="dita"/></codeph>,
            <codeph><xref href="./CREATE_FUNCTION.xml#topic1" type="topic" format="dita"/></codeph>,
            <codeph><xref href="./DROP_CONVERSION.xml#topic1" type="topic" format="dita"
        /></codeph></p></section></body></topic>
